package com.fmatos.amazingwallpapers.image.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

@Deprecated
public class AlbumsDatabaseOpenHelper extends SQLiteOpenHelper {

	public static final String TABLE_ALBUMS = "albums";
	private static final String DATABASE_NAME = TABLE_ALBUMS + ".db";
	private static final int DATABASE_VERSION = 7;
	
	public static final String COLUMN_URL = "url";		 // represents url from where to obtain the photo
	public static final String COLUMN_NAME = "name";	 // represents unique name as given by the server	
	public static final String COLUMN_NICE_NAME = "nice_name"; // represents user customizable name
	public static final String COLUMN_UPDATE_TIME = "update_time";
	public static final String COLUMN_FAVORITE = "favorite";
	public static final String COLUMN_AUTO_UPDATE = "auto_update";

	public static final String[] ALL_COLUMNS = { 
			AlbumsDatabaseOpenHelper.COLUMN_NAME,
			AlbumsDatabaseOpenHelper.COLUMN_URL,
			AlbumsDatabaseOpenHelper.COLUMN_NICE_NAME,
			AlbumsDatabaseOpenHelper.COLUMN_UPDATE_TIME,
			AlbumsDatabaseOpenHelper.COLUMN_FAVORITE,
			AlbumsDatabaseOpenHelper.COLUMN_AUTO_UPDATE
			};
	
	private static final String TAG = AlbumsDatabaseOpenHelper.class.getSimpleName();

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_ALBUMS + "(" 
			+ COLUMN_NAME  + " text primary key  not null," 
			+ COLUMN_URL + " text,"
			+ COLUMN_NICE_NAME + " text,"
			
			+ COLUMN_UPDATE_TIME + " long default null,"
			+ COLUMN_FAVORITE + " boolean,"
			+ COLUMN_AUTO_UPDATE + " boolean "
			+ ");";	

	public AlbumsDatabaseOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		Log.d(TAG, DATABASE_CREATE);
		database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG,
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ALBUMS);
		onCreate(db);
	}
}
